package com.example.ymm.modules1.controller.ms;

import com.example.ymm.model.CommonResult;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.controller.BaseController;
import com.example.ymm.modules1.entity.ms.DDepartment;
import com.example.ymm.modules1.entity.ms.DEmployee;
import com.example.ymm.modules1.query.ms.DDepartmentQueryCriteria;
import com.example.ymm.modules1.query.ms.DEmployeeQueryCriteria;
import com.example.ymm.modules1.service.ms.DDepartmentService;
import com.example.ymm.modules1.service.ms.DEmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/hl/sys/ms/department")
@Api(tags = "ms 部门管理")
@Slf4j
public class MsDepartmentController extends BaseController {

    @Autowired
    DDepartmentService dDepartmentService;

    @Autowired
    DEmployeeService dEmployeeService;

    @ApiOperation(value = "部门树形列表")
    @PostMapping("/departmentTreeList")
    public CommonResult departmentTreeList() {
        try{
            List<DDepartment> list = dDepartmentService.getTreeList();
            return CommonResult.success(list,"获取成功");
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return CommonResult.error(e.getMessage());
        }
    }


    @ApiOperation(value = "部门分页列表")
    @PostMapping("/departmentList")
    public CommonResult departmentList(DDepartmentQueryCriteria criteria, YmPageDto ymPage) {
        try{
            TableList<DDepartment> list = dDepartmentService.list(criteria, ymPage);
            return CommonResult.success(list,"获取成功");
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return CommonResult.error(e.getMessage());
        }
    }

    @ApiOperation(value = "员工列表")
    @PostMapping("/employeeList")
    public CommonResult employeeList(@Valid DEmployeeQueryCriteria criteria, YmPageDto ymPage) {
        try{
            TableList<DEmployee> list = dEmployeeService.list(criteria,ymPage);
            return CommonResult.success(list,"获取成功");
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return CommonResult.error(e.getMessage());
        }
    }


}
